package org.daochong.fastdev.funcs;

import java.sql.SQLException;

import org.daochong.fastdev.Context;
import org.daochong.fastdev.Function;
import org.daochong.lang.BeanUtil;
import org.daochong.lang.StringUtils;

public class VarFunction implements Function {

	public boolean is(String id) {
		return id == null ? false : (id.startsWith("var.") || "var".equals(id));
	}

	public void exec(String key, String prop, Context context) throws SQLException {
		if (StringUtils.isEmpty(key) || StringUtils.isEmpty(prop) || context == null)
			return;
		if (key.startsWith("var.set")) {
			String[] ar = prop.split(",");
			if (ar.length != 2)
				return;
			BeanUtil.setValue(context, ar[0].trim(), ar[1].trim());
		}
	}

}
